package xyz.zichengdulin.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.zichengdulin.pojo.Clazz;
import xyz.zichengdulin.pojo.ClazzQueryParam;
import xyz.zichengdulin.pojo.PageResult;
import xyz.zichengdulin.pojo.Result;
import xyz.zichengdulin.service.ClazzService;
import xyz.zichengdulin.service.EmpService;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;
    @Autowired
    private EmpService empService;

    /**
     * 用于班级列表数据的条件分页查询
     *
     * @return
     */
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam) {
        log.info("班级信息分页查询:{}", clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }

//    /**
//     * 查询全部班主任/员工信息
//     *
//     * @return
//     */
//    @GetMapping("/list")
//    public Result listEmp() {
//        log.info("查询全部班主任/员工:{}", empService);
//        List<Emp> listResult = empService.listEmp();
//        return Result.success(listResult);
//    }

    /**
     * 用于删除班级信息
     *
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据ID删除班级:{}", id);
        clazzService.delete(id);
        return Result.success();
    }

    /**
     * 用于新增班级
     *
     * @param clazz
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody Clazz clazz) {
        log.info("新增班级信息:{}", clazz);
        clazzService.insert(clazz);
        return Result.success();
    }

    /**
     * 查询全部班级信息
     * @return
     */
    @GetMapping("/list")
    public Result getInfo(){
        log.info("查询所有班级信息:{}");
        List<Clazz> clazzlist = clazzService.getInfo();
        return Result.success(clazzlist);
    }

    /**
     * 根据id查询班级信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getInfoById(@PathVariable Integer id) {
        log.info("根据id查询班级信息:()", id);
        Clazz clazz = clazzService.getInfoById(id);
        return Result.success(clazz);
    }

    /**
     * 修改班级
     *
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        log.info("修改班级:{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }




}
